package com.midea.ai.air.ui.home.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.midea.ai.air.R;
import com.midea.ai.air.ui.home.data.AdviceGridItem;

import java.util.List;

/**
 * Created by ouyangdi on 2016/3/9.
 * 健康指数GridView的Adapter
 */
public class AdviceGridAdapter extends ArrayAdapter<AdviceGridItem> {
    private LayoutInflater mInflater;

    public AdviceGridAdapter(Context context, int resource, List<AdviceGridItem> items) {
        super(context, resource, items);
        mInflater = LayoutInflater.from(context);
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        AdviceGridItem item = getItem(position);
        ViewHolder holder;

        if(convertView == null) {
            convertView = mInflater.inflate(R.layout.grid_item_advice, parent, false);
            holder = new ViewHolder();
            holder.ivIcon = (ImageView)convertView.findViewById(R.id.iv_icon_advice);
            holder.tvState = (TextView)convertView.findViewById(R.id.tv_state_advice);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder)convertView.getTag();
        }

        holder.ivIcon.setImageResource(item.getResIdIcon());
        holder.tvState.setText(item.getStrState());
        return convertView;
    }

    private class ViewHolder {
        public ImageView ivIcon;
        public TextView tvState;
    }
}
